home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1992 June: ROMin Holiday / ADC Developer CD (1992-06) (''ROMin Holiday'')_iso / Developer Connection - 06-1992.iso / Developer Essentials / DTS Sample Code / Snippets / Toolbox & IAC / AppleEvents / AECoercion / Read Me • AECoercionINIT < prev    next >
Encoding:
Text File  |  1991-12-04  |  3.0 KB  |  59 lines  |  [TEXT/MPS ]

  1. This is a small sample of how YOU (yes, you) can add functionality
  2. to ANYONE's AppleEvent aware application.
  3. As you read in Inside Mac VI, The AppleEvent manager provides facilities
  4. for coercing (changing) one type of AppleEvent data to another.  It has some
  5. built-in coercions, and it allows you to make your own for your application.
  6.  
  7. BUT, it also allows you to create SYSTEM level coercion routines.
  8. If you create a system level coercer, that means that ANYONE on that
  9. machine can use it, and they may never even know that they did!
  10. Take an example;
  11. Someone  has created an Application that returns graphic images
  12. in AppleEvents, but that weasel ONLY returns them as TIFF, since he or
  13. she hates PICT.
  14. Another application asks for the graphic in the first application's window with a
  15. GetData event.
  16. The snobby application returns a TIFF image.
  17. The asking application doesn't know TIFF, and does this;
  18. myErr = AEGetParamDesc(reply, keyDirectObject, typePICT, &theData);
  19. Oh No!  They get back an error, errAECoercionFail, because the AppleEvent Manager
  20. on its own can't change the returned TIFF into a PICT.
  21. Enter our hero (you)
  22. You are a really smart graphic person, and you know all about converting
  23. PICT to TIFF.  You make a coercion routine that converts PICT to TIFF,
  24. and install it as a System coercion handler.
  25. Then, when the TIFF unaware app does this;
  26. myErr = AEGetParamDesc(reply, keyDirectObject, typePICT, &theData);
  27. The AppleEvent manager KNOWS that you have installed a converter for TIFF to PICT
  28. and calls your converter.  You do the job, and the asking application gets
  29. a PICT without even knowing that a coercion happened!  It's Magic!
  30.  
  31. Coercion routines are very powerful, you can add functonality to all the 
  32. applications on a machine by creating and installing converters from one type to 
  33. another.  The possibilities are limitless on the types of conversions you 
  34. can perform.
  35.  
  36. So here's an example of how to write  an INIT that installs some system coercion
  37. routines on a machine.  It installs two kinda trivial converters, that convert from
  38. a PString type (my own type, the AE Registry does not define a PString) to 
  39. typeChar, and vice-versa [Note: If you write a converter, please write one
  40. that converts in both directions, it'll be much more useful that way].
  41. I use this coercion in some sample code I wrote, so I can work easily with the
  42. Object Model (which expects typeChar for many things) and the Mac ToolBox (which
  43. likes PStrings for many things).
  44.  
  45. After the installation, any application that tries to get a typeChar as a 
  46. typeMyPString will work smoothly, without having to know how to do the conversion 
  47. themselves.
  48.  
  49. Obviously, your converter will be a lot more useful than mine.  Maybe you will write 
  50. the PICT to TIFF, or TEXT to PICT, or whatever.
  51.  
  52. I actually have been waiting for someone in the commercial world to do this 
  53. already, I think there's money in it.  
  54.  
  55. But anyway, look at the sample, read the section on coercion routines CAREFULLY,
  56. and see what you can come up with to help the world!
  57.  
  58. C.K. Haun
  59. Apple Developer Tech Support